package org.cbg.panel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;

import org.cbg.bean.SearchGoodsBean;
import org.cbg.btn.TrslationBtn;
import org.cbg.frame.TrslationMainJframe;
import org.cbg.until.TraslationTableUntil;
import org.come.Frame.ZhuFrame;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.CutButtonImage;
import org.come.until.GsonUtil;

import com.tool.tcpimg.UIUtils;

 

/**
 * 我要买灵宝面板
 * 
 * @author Administrator
 * 
 */

public class TraslationWantBuyLingbaoJpanel extends JLayeredPane {

    private static TraslationWantBuyLingbaoJpanel traslationWantBuyLingbaoJpanel;

    /**
     * 下拉框：左，中，右；页码,上排序,下排序
     */
    private JLabel yema, upSort, downSort;// , chooseMiddle,
    // chooseRight,chooseLeft,

    /**
     * 下拉框列表
     */
    // private TraslationSelectOptionJpanel chooseLeftModel;// ,
    // chooseMiddleModel,
    // chooseRightModel

    /**
     * 下拉框是否下拉（0是下拉，1是没下拉）排序标识（0为默认排序， 1 为升序 ，2 为降序）
     */
    private int showOrder = 0;// leftFlag = 1, middleFlag = 1, rightFlag = 1

    /**
     * 页码按钮，首页，末页 , 左箭头, 右箭头
     */
    private TrslationBtn shouye, moye, leftArrows, rightArrows;

    /**
     * 当前页码 最大页码
     *
     */
    private int dangqianyeshu = 1, zuidayema = 50;

    /**
     * 表格
     */
    private JScrollPane jScrollPane;

    public TraslationWantBuyLingbaoJpanel() {
        traslationWantBuyLingbaoJpanel = this;

        this.setPreferredSize(new Dimension(760, 460));
        this.setOpaque(false);
        this.setLayout(null);

        jScrollPane = new JScrollPane();
        jScrollPane.setBounds(8, 63, 750, 372);
        TraslationTableUntil.TableModel(jScrollPane, 10);
        jScrollPane.getVerticalScrollBar().setUnitIncrement(50);

        this.add(jScrollPane, 10, -1);

        /**
         * 页码设置
         */
        yema = new JLabel(dangqianyeshu + "/" + zuidayema);
        yema.setBounds(258+91, 442, 58, 17);
        yema.setForeground(UIUtils.COLOR_cbg8);
        yema.setOpaque(false);

        yema.setHorizontalAlignment(SwingConstants.CENTER);
        this.add(yema);

        shouye = new TrslationBtn("inkImg/number/b4/fy1.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "");
        shouye.setBounds(287, 442, 40, 20);
        this.add(shouye);
        shouye.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu != 1) {
                    dangqianyeshu = 1;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 将搜索信息传给服务器 1、初始化协议
                     * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏)
                     * 3、确认是否有二级搜索( 1 全部 2 召唤兽装备 3 地煞星符 4 宝石 5 召唤兽饰品 6 孩子装备 7 其它
                     * 8 1-14称 9 特殊召唤兽 10 高级守护 11 神兽 12 常规装备 13 神兵 14 仙器 15 配饰
                     * 16 护身符 17 灵宝 18 符石 19 道具类 20 召唤兽类 21 装备类 22 灵宝类 0 没有二级分类
                     * ) 4、传递当前页码 5、搜索条件的整合 6、转换为json字符串 7、上传给服务器
                     *
                     * start
                     */
                    SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                    searchGoodsBean.setSaletype(6);
                    // searchGoodsBean.setContiontype("16");// 根据第一个下拉框改变
                    // searchGoodsBean.setSalename("等级=" +
                    // chooseMiddle.getText() + "-" + chooseRight.getText());
                    searchGoodsBean.setPageNum(dangqianyeshu);
                    searchGoodsBean.setOrder(showOrder);
                    String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                    SendMessageUntil.toServer(sendmes);
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(6);
                    /**
                     * end
                     */
                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已在首页");
                }

            }
        });

        leftArrows = new TrslationBtn("inkImg/number/b4/fy2.png", 1);
        leftArrows.setBounds(326, 442, 19, 20);
        this.add(leftArrows);
        leftArrows.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu > 1) {
                    dangqianyeshu--;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 将搜索信息传给服务器 1、初始化协议
                     * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏)
                     * 3、确认是否有二级搜索( 1 全部 2 召唤兽装备 3 地煞星符 4 宝石 5 召唤兽饰品 6 孩子装备 7 其它
                     * 8 1-14称 9 特殊召唤兽 10 高级守护 11 神兽 12 常规装备 13 神兵 14 仙器 15 配饰
                     * 16 护身符 17 灵宝 18 符石 19 道具类 20 召唤兽类 21 装备类 22 灵宝类 0 没有二级分类
                     * ) 4、传递当前页码 5、搜索条件的整合 6、转换为json字符串 7、上传给服务器
                     *
                     * start
                     */
                    SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                    searchGoodsBean.setSaletype(6);
                    // searchGoodsBean.setContiontype("16");// 根据第一个下拉框改变
                    // searchGoodsBean.setSalename("等级=" +
                    // chooseMiddle.getText() + "-" + chooseRight.getText());
                    searchGoodsBean.setPageNum(dangqianyeshu);
                    searchGoodsBean.setOrder(showOrder);
                    String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                    SendMessageUntil.toServer(sendmes);
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(6);
                    /**
                     * end
                     */
                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已经没有上一页了");
                }
            }
        });

        moye = new TrslationBtn("inkImg/number/b4/fy4.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "");
        moye.setBounds(433, 442, 40, 20);
        this.add(moye);

        moye.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu != zuidayema) {
                    dangqianyeshu = zuidayema;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 将搜索信息传给服务器 1、初始化协议
                     * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏)
                     * 3、确认是否有二级搜索( 1 全部 2 召唤兽装备 3 地煞星符 4 宝石 5 召唤兽饰品 6 孩子装备 7 其它
                     * 8 1-14称 9 特殊召唤兽 10 高级守护 11 神兽 12 常规装备 13 神兵 14 仙器 15 配饰
                     * 16 护身符 17 灵宝 18 符石 19 道具类 20 召唤兽类 21 装备类 22 灵宝类 0 没有二级分类
                     * ) 4、传递当前页码 5、搜索条件的整合 6、转换为json字符串 7、上传给服务器
                     *
                     * start
                     */
                    SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                    searchGoodsBean.setSaletype(6);
                    // searchGoodsBean.setContiontype("16");// 根据第一个下拉框改变
                    // searchGoodsBean.setSalename("等级=" +
                    // chooseMiddle.getText() + "-" + chooseRight.getText());
                    searchGoodsBean.setPageNum(dangqianyeshu);
                    searchGoodsBean.setOrder(showOrder);
                    String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                    SendMessageUntil.toServer(sendmes);
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(6);
                    /**
                     * end
                     */

                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已在末页");
                }
            }
        });

        rightArrows = new TrslationBtn("inkImg/number/b4/fy3.png", 1);
        rightArrows.setBounds(411, 442, 19, 20);
        this.add(rightArrows);
        rightArrows.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu < zuidayema) {
                    dangqianyeshu++;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 将搜索信息传给服务器 1、初始化协议
                     * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏)
                     * 3、确认是否有二级搜索( 1 全部 2 召唤兽装备 3 地煞星符 4 宝石 5 召唤兽饰品 6 孩子装备 7 其它
                     * 8 1-14称 9 特殊召唤兽 10 高级守护 11 神兽 12 常规装备 13 神兵 14 仙器 15 配饰
                     * 16 护身符 17 灵宝 18 符石 19 道具类 20 召唤兽类 21 装备类 22 灵宝类 0 没有二级分类
                     * ) 4、传递当前页码 5、搜索条件的整合 6、转换为json字符串 7、上传给服务器
                     *
                     * start
                     */
                    SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                    searchGoodsBean.setSaletype(6);
                    searchGoodsBean.setPageNum(dangqianyeshu);
                    searchGoodsBean.setOrder(showOrder);
                    String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                    SendMessageUntil.toServer(sendmes);
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(6);
                    /**
                     * end
                     */
                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已经没有下一页了");
                }
            }
        });

        /**
         * 排序
         */
        upSort = new JLabel();
        upSort.setBounds(280, 38, 10, 18);
        upSort.setBorder(null);
        upSort.setBackground(null);
        upSort.setOpaque(false);
        upSort.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1002.png", 10, 18));
        this.add(upSort);
        upSort.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                upSort.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1003.png", 10, 18));
                downSort.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1004.png", 10, 18));
                dangqianyeshu = 1;
                showOrder = 1;
                /**
                 * 将搜索信息传给服务器 1、初始化协议
                 * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏)
                 * 3、确认是否有二级搜索( 1 全部 2 召唤兽装备 3 地煞星符 4 宝石 5 召唤兽饰品 6 孩子装备 7 其它 8
                 * 1-14称 9 特殊召唤兽 10 高级守护 11 神兽 12 常规装备 13 神兵 14 仙器 15 配饰 16 护身符
                 * 17 灵宝 18 符石 19 道具类 20 召唤兽类 21 装备类 22 灵宝类 0 没有二级分类 ) 4、传递当前页码
                 * 5、搜索条件的整合 6、转换为json字符串 7、上传给服务器
                 *
                 * start
                 */
                SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                searchGoodsBean.setSaletype(6);
                searchGoodsBean.setPageNum(dangqianyeshu);
                searchGoodsBean.setOrder(showOrder);
                String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                        GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                SendMessageUntil.toServer(sendmes);
                TrslationMainJframe.getTrslationMainJframe().setPanelOpen(6);
                /**
                 * end
                 */
            }
        });

        downSort = new JLabel();
        downSort.setBounds(296, 39, 10, 18);
        downSort.setBorder(null);
        downSort.setBackground(null);
        downSort.setOpaque(false);
        downSort.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1004.png", 10, 18));
        this.add(downSort);
        downSort.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                upSort.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1002.png", 10, 18));
                downSort.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1005.png", 10, 18));
                dangqianyeshu = 1;
                showOrder = 2;
                /**
                 * 将搜索信息传给服务器 1、初始化协议
                 * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏)
                 * 3、确认是否有二级搜索( 1 全部 2 召唤兽装备 3 地煞星符 4 宝石 5 召唤兽饰品 6 孩子装备 7 其它 8
                 * 1-14称 9 特殊召唤兽 10 高级守护 11 神兽 12 常规装备 13 神兵 14 仙器 15 配饰 16 护身符
                 * 17 灵宝 18 符石 19 道具类 20 召唤兽类 21 装备类 22 灵宝类 0 没有二级分类 ) 4、传递当前页码
                 * 5、搜索条件的整合 6、转换为json字符串 7、上传给服务器
                 *
                 * start
                 */
                SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                searchGoodsBean.setSaletype(6);
                // searchGoodsBean.setContiontype("16");// 根据第一个下拉框改变
                // searchGoodsBean.setSalename("等级=" + chooseMiddle.getText() +
                // "-" + chooseRight.getText());
                searchGoodsBean.setPageNum(dangqianyeshu);
                searchGoodsBean.setOrder(showOrder);
                String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                        GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                SendMessageUntil.toServer(sendmes);
                TrslationMainJframe.getTrslationMainJframe().setPanelOpen(6);
                /**
                 * end
                 */
            }
        });

    }

    private ImageIcon icon1;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon1 == null) {
            icon1 = new ImageIcon("inkImg/number/b4/scxq.png");

        }
        g.drawImage(icon1.getImage(), 0, 5, 760, 55,  this);

    }

    /**
     * 刷新页面的页码
     *
     * @param dangqianyema
     * @param zuidayema
     *
     */
    public void setPage(int zuidayema) {
        this.zuidayema = zuidayema;
        yema.setText(this.dangqianyeshu + "/" + this.zuidayema);
    }

    public static TraslationWantBuyLingbaoJpanel getTraslationWantBuyLingbaoJpanel() {
        return traslationWantBuyLingbaoJpanel;
    }

    public static void setTraslationWantBuyLingbaoJpanel(TraslationWantBuyLingbaoJpanel traslationWantBuyLingbaoJpanel) {
        TraslationWantBuyLingbaoJpanel.traslationWantBuyLingbaoJpanel = traslationWantBuyLingbaoJpanel;
    }

    public JLabel getYema() {
        return yema;
    }

    public void setYema(JLabel yema) {
        this.yema = yema;
    }

    public JLabel getUpSort() {
        return upSort;
    }

    public void setUpSort(JLabel upSort) {
        this.upSort = upSort;
    }

    public JLabel getDownSort() {
        return downSort;
    }

    public void setDownSort(JLabel downSort) {
        this.downSort = downSort;
    }

    public TrslationBtn getShouye() {
        return shouye;
    }

    public void setShouye(TrslationBtn shouye) {
        this.shouye = shouye;
    }

    public TrslationBtn getMoye() {
        return moye;
    }

    public void setMoye(TrslationBtn moye) {
        this.moye = moye;
    }

    public TrslationBtn getLeftArrows() {
        return leftArrows;
    }

    public void setLeftArrows(TrslationBtn leftArrows) {
        this.leftArrows = leftArrows;
    }

    public TrslationBtn getRightArrows() {
        return rightArrows;
    }

    public void setRightArrows(TrslationBtn rightArrows) {
        this.rightArrows = rightArrows;
    }

    public ImageIcon getIcon1() {
        return icon1;
    }

    public void setIcon1(ImageIcon icon1) {
        this.icon1 = icon1;
    }

    public int getDangqianyeshu() {
        return dangqianyeshu;
    }

    public void setDangqianyeshu(int dangqianyeshu) {
        this.dangqianyeshu = dangqianyeshu;
    }

    public int getZuidayema() {
        return zuidayema;
    }

    public void setZuidayema(int zuidayema) {
        this.zuidayema = zuidayema;
    }

    public JScrollPane getjScrollPane() {
        return jScrollPane;
    }

    public void setjScrollPane(JScrollPane jScrollPane) {
        this.jScrollPane = jScrollPane;
    }

    public int getShowOrder() {
        return showOrder;
    }

    public void setShowOrder(int showOrder) {
        this.showOrder = showOrder;
    }

}
